package com.wsoft.system.service.impl;

import com.wsoft.core.service.RedisService;
import com.wsoft.system.mapper.CommonMapper;
import com.wsoft.system.service.CommonMyBatisService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 公共资源
 *
 * @author: zhanggukai
 * @date: 2024年07月23日 16:03
 */
@Service
public class CommonMyBatisServiceImpl implements CommonMyBatisService {
    @Resource
    private RedisService redisService;
    @Resource
    private CommonMapper commonMapper;

    /**
     * 判断表中是否存在列
     * @param tableName
     * @param filedName
     * @return
     */
    @Override
    public int getFieldExists(String tableName, String filedName) {
        String key = "tableFiled:" + tableName + ":" + filedName;
        Object obj = redisService.get(key);
        if(obj == null) {
            int ifExit = commonMapper.getFieldExists(tableName, filedName);
            redisService.set(key, ifExit);
            return ifExit;
        }
        return Integer.parseInt(obj.toString());
    }
}
